#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=1e6+5;
int T;
ll sum,n,m,L,V,d[M],v[N],a[M],p[N],cnt[M];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>L>>V;
        for(ll i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
            cnt[a[i]]++;
        }
        for(ll i=1;i<=m;i++){
            cin>>p[i];
        }
    }
    if(cnt[0]==n){
        for(ll i=1;i<=n;i++){
            if(v[i]>V&&d[i]<p[m]){
                sum++;
            }
        }
    }
    cout<<sum<<" "<<m-1;
return 0;
}
